﻿using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows;

namespace Desktop.Converters
{
    [ValueConversion(typeof(object), typeof(string))]
    public class ActivityNameTruncator : IValueConverter
    {
        #region Constants

        private const int TAB_NAME_MAX_LENGTH = 32;

        #endregion

        #region Methods

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string name = value.ToString();
            int length = (name.Length < TAB_NAME_MAX_LENGTH) ? name.Length : TAB_NAME_MAX_LENGTH;
            return name.Substring(0, length);
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }

        #endregion
    }
}